#include "HookProcManager.h"
#include "tools/helpMacros.h"




#include SD_TL_PLATFORM_IMPL_INC(.,HookProcManager)


using namespace sd::hp;



Library::Library( const std::string& name )
{
	impl_.reset( new impl::LibraryImpl( name ) );
}

Library::Library( const Library& ref )
{
	impl_ = ref.impl_;
}

const std::string& Library::getName()const
{
	return impl_->getName();
}


HookedProcess& HookedProcess::getInstance()
{
	static HookedProcess proc;
	return proc;
}


HookedProcess::HookedProcess():impl_( impl::HookedProcessImplementation::getInstance() ), softDeactivateMode_(true), autolockingMode_(true)
{}


LibraryRef HookedProcess::getLibrary( const std::string& name )
{
	return * new Library( name );
}

void HookedProcess::lock()
{
	impl_.lock();
}

bool HookedProcess::checkLockedThreadsActiveCode(const void* function)const
{
	return impl_.checkLockedThreadsActiveCode(function);
}


void HookedProcess::unlock()
{
	impl_.unlock();
}

bool HookedProcess::isLocked()
{
	return impl_.isLocked();
}


HookedProcess::Hooks::iterator HookedProcess::findHook( const std::string& name, const std::string& library )
{
	//TODO: change to boost index
	struct HookDummy: public HookBase
	{
		HookDummy( const std::string& name, const std::string& library ): HookBase( name, library ){}
		virtual void* getInnerCallbackPtrVirt(){ return 0; }
		virtual void setDummyActive(bool){}
	} dummy( name, library );
	return hooks_.find( &dummy );	
}


